package com.example.design.filter.filter;


import com.example.design.DateUtils;
import com.example.design.filter.ScheduleFilter;
import com.example.design.filter.context.PreSaleScheduleContext;
import com.example.design.filter.context.ScheduleContext;

/**
 * 售前白班&夜班班次1:1预分配 仅售前排班时使用
 */
public class ShiftAllocateFilter implements ScheduleFilter {

    public static final ScheduleFilter instance = new ShiftAllocateFilter();

    @Override
    public void filter(ScheduleContext context) {
        String dateKey = context.getScheduleDate().format(DateUtils.FORMAT_YYYYMMDD);
        Integer totalShift = context.getShiftMap().get(dateKey);
        totalShift = totalShift == null ? 0 : totalShift;
        context.setShiftNum(totalShift);

        if (context instanceof PreSaleScheduleContext) {
            int dayShiftNum = totalShift % 2 > 0 ? totalShift / 2 + 1 : totalShift / 2;
            ((PreSaleScheduleContext) context).setDayShiftNum(dayShiftNum);
        }
    }
}
